from rest_framework import serializers
from .models import PhaseSummary

class PhaseSummaryListSerializer(serializers.ModelSerializer):
    """报告列表序列化器"""
    report_type_display = serializers.CharField(source='get_report_type_display', read_only=True)
    report_style_display = serializers.CharField(source='get_report_style_display', read_only=True)
    workflow_name_display = serializers.CharField(source='get_workflow_name_display', read_only=True)
    created_at_display = serializers.SerializerMethodField()

    class Meta:
        model = PhaseSummary
        fields = ['id', 'title', 'report_type', 'report_type_display', 
                 'report_style', 'report_style_display', 
                 'workflow_name', 'workflow_name_display',
                 'created_at', 'created_at_display', 'industry']

    def get_created_at_display(self, obj):
        """格式化时间为北京时间"""
        return obj.created_at.astimezone().strftime('%Y年%m月%d日 %H:%M')

class PhaseSummarySerializer(serializers.ModelSerializer):
    """阶段总结序列化器"""
    class Meta:
        model = PhaseSummary
        fields = ['id', 'title', 'content', 'workflow_name', 
                 'report_type', 'report_style', 'industry',
                 'created_at', 'updated_at']
        read_only_fields = ['created_at', 'updated_at']

class PhaseSummaryCreateSerializer(serializers.Serializer):
    """阶段总结创建序列化器"""
    context = serializers.CharField(help_text='生成阶段总结的上下文')
    report_type = serializers.IntegerField(required=False, default=0)
    report_style = serializers.IntegerField(required=False, default=0)
    industry = serializers.CharField(required=False, allow_blank=True)
